import { CompatibilityTree } from '../../compatibility-tree'
import axios from 'axios'

/**
 * AI驱动的依赖分析服务
 * 集成GitHub Copilot和DeepCode功能
 */
export class DependencyAnalyzer {
  private tree: CompatibilityTree

  constructor(tree: CompatibilityTree) {
    this.tree = tree
  }

  /**
   * 获取依赖版本推荐
   * @returns 包含推荐版本的依赖映射表
   */
  async recommendVersions(): Promise<Record<string, string>> {
    const projectDeps = this.tree.getDependencies()
    const { data } = await axios.post('https://api.copilot.ai/analyze', {
      dependencies: projectDeps
    })
    return data.recommendations
  }

  /**
   * 检测潜在依赖冲突
   * @returns 冲突报告对象
   */
  async detectConflicts(): Promise<ConflictReport> {
    const depGraph = this.tree.toDependencyGraph()
    const { data } = await axios.post('https://api.deepcode.ai/check', {
      dependencyGraph: depGraph
    })
    
    return {
      critical: data.criticalConflicts,
      warnings: data.potentialIssues,
      suggestions: data.resolutions
    }
  }
}

interface ConflictReport {
  critical: string[]
  warnings: string[] 
  suggestions: string[]
}